home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / C / XMSSTUFF.ZIP / XMSSTUFF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-05  |  3.4 KB  |  225 lines

  1. #include <dos.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <memory.h>
  5. #include <malloc.h>
  6. #include "xmsstuff.h"
  7.  
  8. int XMS_detect( void )
  9. {
  10.     int found;
  11.     _asm
  12.     {
  13.         mov ax, 4300h
  14.         int 2Fh
  15.         cmp al, 80h
  16.         jne noxms
  17.         mov ax, 1
  18.         mov found, ax
  19.         jp done
  20.     noxms:
  21.         mov ax, 0
  22.         mov found, ax
  23.     done:
  24.     }
  25.     return found;
  26. }
  27.  
  28. void XMS_ini( void )
  29. {
  30.     _asm
  31.     {
  32.         mov ax,4310h
  33.         int 2Fh
  34.         mov word ptr [XMSControl],bx
  35.         mov word ptr [XMSControl+2],es
  36.  
  37.         mov ah, 00h
  38.         call [XMSControl]
  39.         mov XMSVersion, ax
  40.     }
  41. }
  42.  
  43. unsigned int XMS_largestavail( void )
  44. {
  45.     unsigned int free;
  46.     _asm
  47.     {
  48.         mov ah, 08h
  49.         call [XMSControl]
  50.         mov free, ax
  51.         mov error, bl;
  52.     }
  53.     return free;
  54. }
  55.  
  56. unsigned int XMS_memavail( void )
  57. {
  58.     unsigned int free;
  59.     _asm
  60.     {
  61.         mov ah, 08h
  62.         call [XMSControl]
  63.         mov free, dx
  64.         mov error, bl;
  65.     }
  66.     return free;
  67. }
  68.  
  69. unsigned int XMS_allocate_block( unsigned int amount )
  70. {
  71.     unsigned int handle;
  72.     unsigned int sucsess;
  73.     _asm
  74.     {
  75.         mov ah, 09h
  76.         mov dx, amount
  77.         call [XMSControl]
  78.         mov sucsess, ax
  79.         mov handle, dx
  80.         mov error, bl;
  81.     }
  82.     return handle;
  83. }
  84.  
  85. int XMS_free_block( unsigned int handle )
  86. {
  87.     unsigned int sucsess;
  88.     _asm
  89.     {
  90.         mov ah, 0Ah
  91.         mov dx, handle
  92.         call [XMSControl]
  93.         mov sucsess, ax
  94.         mov error, bl;
  95.     }
  96.     return sucsess;
  97. }
  98.  
  99. char XMS_handles_free( unsigned int handle )
  100. {
  101.     unsigned int sucsess;
  102.     unsigned char handles;
  103.     _asm
  104.     {
  105.         mov ah, 0Eh
  106.         mov dx, handle
  107.         call [XMSControl]
  108.         mov sucsess, ax
  109.         mov handles, bl
  110.         mov error, bl;
  111.     }
  112.     if( sucsess )
  113.         return handles;
  114.     else
  115.         return sucsess;
  116. }
  117.  
  118.  
  119. int XMS_move_block( struct ExtMemMoveStruct _far *structin )
  120. {
  121.     unsigned int sucsess;
  122.     _asm
  123.     {
  124.         push ds
  125.         push si
  126.         mov ah, 0Bh
  127.         lds si, structin
  128.         call [XMSControl]
  129.         mov sucsess, ax
  130.         mov error, bl
  131.         pop si
  132.         pop ds
  133.     }
  134.     return sucsess;
  135. }
  136.  
  137. char _far *XMS_lock_block( unsigned int handle )
  138. {
  139.     char _far *temp;
  140.     unsigned int segpart;
  141.     unsigned int offpart;
  142.     unsigned int sucsess;
  143.     _asm
  144.     {
  145.         mov ah, 0Ch
  146.         mov dx, handle
  147.         call [XMSControl]
  148.         mov sucsess, ax
  149.         mov segpart, dx
  150.         mov offpart, bx
  151.         mov error, bl;
  152.     }
  153.  
  154.     FP_SEG(temp) = segpart;
  155.     FP_OFF(temp) = offpart;
  156.     if( sucsess )
  157.         return temp;
  158.     else
  159.         return NULL;
  160. }
  161.  
  162. int XMS_unlock_block( unsigned int handle )
  163. {
  164.     unsigned int sucsess;
  165.     _asm
  166.     {
  167.         mov ah, 0Dh
  168.         mov dx, handle
  169.         call [XMSControl]
  170.         mov sucsess, ax
  171.         mov error, bl;
  172.     }
  173.     return sucsess;
  174. }
  175.  
  176. int XMSE_xms_to_con( unsigned int handle, char _far *data, unsigned int length )
  177. {
  178.     struct ExtMemMoveStruct mystruct;
  179.     mystruct.Length = length;
  180.     mystruct.SourceHandle = handle;
  181.     mystruct.SourceOffset = 0x00;
  182.     mystruct.DestHandle = 0x00;
  183.     mystruct.DestOffset = ((long)FP_SEG(data) << 16) + FP_OFF(data);
  184.  
  185.     return XMS_move_block( &mystruct );
  186. }
  187.  
  188. int XMSE_con_to_xms( unsigned int handle, char _far *data, unsigned int length )
  189. {
  190.     struct ExtMemMoveStruct mystruct;
  191.     mystruct.Length = length;
  192.     mystruct.SourceHandle = 0x00;
  193.     mystruct.SourceOffset = ((long)FP_SEG(data) << 16) + FP_OFF(data);
  194.     mystruct.DestHandle = handle;
  195.     mystruct.DestOffset = 0x00;
  196.  
  197.     return XMS_move_block( &mystruct );
  198. }
  199.  
  200. int XMS_enable_A20( void )
  201. {
  202.     unsigned int sucsess;
  203.     _asm
  204.     {
  205.         mov ah, 05h
  206.         call [XMSControl]
  207.         mov sucsess, ax
  208.     }
  209.     return sucsess;
  210. }
  211.  
  212. int XMS_disable_A20( void )
  213. {
  214.     unsigned int sucsess;
  215.     _asm
  216.     {
  217.         mov ah, 06h
  218.         call [XMSControl]
  219.         mov sucsess, ax
  220.     }
  221.     return sucsess;
  222. }
  223.  
  224.  
  225.